module.exports = app => {
  class FileController extends app.Controller {
    async list (){
        try {
            let list = await this.ctx.service.file.list()
            this.ctx.body = {
                code: 200,
                message: `成功读取文件列表`,
                data: list
            }
        } catch (error) {
            console.log(error)
        }
    }

    async upload (){
        try {
            const body = this.ctx.request.body
            const result = await this.ctx.service.file.upload(body)
            this.ctx.body = {
                code: 200,
                success: true,
                data: result
            }
        } catch (error) {
            console.log(error)
        }
    }

    async remove (){
        try {
            const fileId = this.ctx.query.fileId
            const result = await this.ctx.service.file.remove(fileId)
            this.ctx.body = {
                code: 200,
                data: result,
                success: true,
            }
        } catch (error) {
            console.log(error)
        }
    }

    async update (){
        try {
            const body = this.ctx.request.body
            const result = await this.ctx.service.file.update(body)
            this.ctx.body = {
                code: 200,
                data: result,
                success: true,
            }
        } catch (error) {
            console.log(error)
        }
    }

    async search (){
        try {
            const query = this.ctx.query
            const result = await this.ctx.service.file.search(query)
            this.ctx.body = {
                code: 200,
                data: result,
                success: true,
            }
        } catch (error) {
            console.log(error)
        }
    }
  }
  return FileController
}
